package com.CMS.server.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * The persistent class for the entity database table.
 * 
 */
@Entity
@Table(name = EntityTokens.BASEENTITY_TABLE)
public class BaseEntity implements Serializable {
    /**
	 * 
	 */
	private static final long serialVersionUID = -4871901547915050019L;

	@Temporal( TemporalType.TIMESTAMP)
    @Column(name = EntityTokens.BASEENTITY_ADD_DATE_COLUMN,nullable=false)
	private Date addDate;

    @Temporal( TemporalType.TIMESTAMP)
	@Column(name = EntityTokens.BASEENTITY_DEL_DATE_COLUMN,nullable=true)
	private Date delDate;

	@Column(name = EntityTokens.BASEENTITY_DESCRIPTION_COLUMN,length=100, nullable = true, unique = false)
	private String description;

	@Column(name = EntityTokens.BASEENTITY_FLAG_DELETE_COLUMN,nullable = false)
	private boolean flagDelete;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = EntityTokens.BASEENTITY_ID_COLUMN)
	private long id;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = EntityTokens.BASEENTITY_MOD_DATE_COLUMN,nullable = false)
	private Date modDate;

    public BaseEntity() {
    	this.addDate = new Date();
    	this.modDate = new Date();
    	this.flagDelete = false;
    }

	public Date getAddDate() {
		return this.addDate;
	}

	public void setAddDate(Date addDate) {
		this.addDate = addDate;
	}

	public Date getDelDate() {
		return this.delDate;
	}

	public void setDelDate(Date delDate) {
		this.delDate = delDate;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean getFlagDelete() {
		return this.flagDelete;
	}

	public void setFlagDelete(boolean flagDelete) {
		this.flagDelete = flagDelete;
	}

	public long getId() {
		return this.id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Date getModDate() {
		return this.modDate;
	}

	public void setModDate(Date modDate) {
		this.modDate = modDate;
	}
	
	@Override
	public boolean equals(Object obj){
		if(this == obj)
			return true;
		if(obj == null)
			return true;
		if(this.getId() == ((BaseEntity)obj).getId())
			return true;
		else
			return false;
	}

	@Override
	public String toString(){
		return getDescription();
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode());
		return result;
	}
}